package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import server.NewsServer;
import serverImp.NewsServerImp;
import entity.News;

public class Update extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		int id=Integer.valueOf(request.getParameter("id"));
		String title = request.getParameter("title");
		String author = request.getParameter("author");
		String content = request.getParameter("content");
		News news = new News(id, title, author, content);
		NewsServer ns = new NewsServerImp();
		if (ns.update(news) > 0) {
			out.print("<script type='text/javascript'>alert('更新成功');location.href='ListServlet';</script>");
		} else {
			out.print("<script type='text/javascript'>alert('更新失败');location.href='ListServlet';</script>");
		}
	}

}
